import socket

# 这个服务端的socket只是负责接受客户端的连接请求
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(('10.211.211.100', 8000))

# 服务器允许最大等待建立连接的个数
server_socket.listen(128)
# 负责接收客户端的连接
socket2, client_addr = server_socket.accept()

while True:
    # 正式开始聊天 tcp用recv
    msg = socket2.recv(1024).decode('utf8')
    if msg == 'quit':
        break
    print(f'来着客户端IP{client_addr[0]},端口号：{client_addr[1]}:{msg}')

    # 给客户端发送消息
    send_msg = input('服务端发送消息 >>')
    socket2.send(send_msg.encode('utf8'))

# 关闭
socket2.close()
server_socket.close()
